// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-

/// EEPROM 
#define EEPROM_MAX_ADDR		4096	// 0x1000

/// SYSTEM (Base 0x0000)

/// COMPASS (Base 0x0100)
#define EE_COMPASS_DECLINATION		0x0100	// float
#define EE_COMPASS_X_MAX			0x0104	// int
#define EE_COMPASS_X_MIN			0x0106	// int
#define EE_COMPASS_Y_MAX			0x0108	// int
#define EE_COMPASS_Y_MIN			0x010A	// int
#define EE_COMPASS_Z_MAX			0x010C	// int
#define EE_COMPASS_Z_MIN			0x010E	// int
#define EE_ACC_OFFSET_X				0x0110	// float
#define EE_ACC_OFFSET_Y				0x0114	// float
#define EE_ACC_OFFSET_Z				0x0118	// float
#define EE_GYRO_OFFSET_ROLL			0x011C	// float
#define EE_GYRO_OFFSET_PITCH		0x0120	// float
#define EE_GYRO_OFFSET_YAW			0x0124	// float

/// How to read/write to EEPROM

/// Read
//  uint8_t temp = eeprom_read_byte((uint8_t *) EE_DATAPOINTER);
//	int16_t temp = eeprom_read_word((const uint16_t *) EE_DATAPOINTER);
//	int32_t temp = eeprom_read_dword((const uint32_t *) EE_DATAPOINTER);
//  read a float
//	eeprom_read_block((void*)&data, (const void*)EE_DATAPOINTER, sizeof(data));

/// Write
//  eeprom_write_byte((uint8_t *) EE_DATAPOINTER, value8);
//	eeprom_write_word((uint16_t *) EE_DATAPOINTER, value16);
//	eeprom_write_dword((uint32_t *) EE_DATAPOINTER, value32);
//  store a float
//	eeprom_write_block((const void *)&data, (void *)EE_DATAPOINTER, sizeof (data));

/// Read from eeprom
float eeprom_read_int (uint16_t ee_address) {
	int value;
	eeprom_read_block((void*)&value, (const void*)ee_address, sizeof(int));
	return value;
}

float eeprom_read_float (uint16_t ee_address) {
	float value;
	eeprom_read_block((void*)&value, (const void*)ee_address, sizeof(float));
	return value;
}

/// Write to eeprom
void eeprom_write_int (uint16_t ee_address, int value) {
	eeprom_write_block((const void *)&value, (void *)ee_address, sizeof(value));
}

void eeprom_write_float (uint16_t ee_address, float value) {
	eeprom_write_block((const void *)&value, (void *)ee_address, sizeof(value));
}
